import http from "../js/http.js"

/*获取微信code*/
function GET_WXCODE() {
	return new Promise((resolve, reject) => {
		uni.login({
			success: (res) => {
				resolve(res.code)
			}
		})
	})
}

// 绑定手机
async function bindUser(data){
	data.code = await GET_WXCODE()
	var sysInfo = uni.getSystemInfoSync()
	if(sysInfo){
		data.phoneModel = `手机品牌:${sysInfo.model};系统:${sysInfo.system};版本:${sysInfo.version}`
	}
	console.log(data.code)
	return http({
		url: '/Api/MiniApp/Bind/User',
		isToken: false,
		// ignore: true,
		data
	})
}
//code直接获取用户信息
async function queryUser(){
	var sysInfo = uni.getSystemInfoSync()
	var phoneModel = ''
	if(sysInfo){
		phoneModel = `手机品牌:${sysInfo.model};系统:${sysInfo.system};版本:${sysInfo.version}`
	}
	return http({
		url: '/Api/MiniApp/Query/User',
		method: 'get',
		
		hideErrorModal: true,
		data: {
			code: await GET_WXCODE(),
			phoneModel
		}
	})
}
//获取rsa加密公钥
function loginKey(){
	return http({
		url: '/IdentityApi/Reader/LoginKey/Js',
		method: 'get',
		isToken: false,
		ignore: true
	})
}
//搜索机构代码
function queryOrgCode(data){
	return http({
		url: '/IdentityApi/Organization/Query/Brief/Information',
		method: 'get',
		isToken: false,
		isLogin: true,
		data,
		without: true
	})
}
//通过手机号获取验证码
function genValidateCode(data){
	return http({
		url: '/api/Sms/GenValidateCode',
		method: 'get',
		isToken: false,
		data
	})
}
//通过手机号修改密码
function resetPsw(data){
	return http({
		url: '/Api/User/ResetPsw',
		data
	})
}
//用户登录时长获取积分
function studentOnline(data){
	return http({
		url: '/Api/Student/OnlineOver30',
		data
	})
}
//图片验证码
function valiCode(data){
	return http({
		method: 'get',
		url: '/IdentityApi/ValidateCode/Get',
		data
	})
}
function readerLogin(data){
	return http({
		isLogin: true,
		url: '/IdentityApi/Reader/NoSip2Login',
		data
	})
}
export {
	GET_WXCODE,
	bindUser,
	queryUser,
	genValidateCode,
	resetPsw,
	loginKey,
	studentOnline,
	queryOrgCode,
	valiCode,
	readerLogin
	
}